<template>
  <body>
  <div>
    <img src="../assets/login-page-bg.jpg" id="pic">
    <h1 class="title11">尊敬的用户，欢迎来到小趴菜商城</h1>
    <div>
      <form>
        <div class="class12">账号&nbsp; : &nbsp;<input id=id type="text" class="text1" v-model="account">
        </div>
        <div class="class13">密码 &nbsp;: &nbsp;<input id=pwd type="password" class="text1" v-model="password ">
        </div>
      </form>
      <div>
        <button type="button" class="class14" @click="login">登录</button>
        <button type="button" class="class15" @click="redirect">注册</button>
      </div>
    </div>
  </div>
  </body>
</template>
<script>

import request from "@/utils/request";
import router from "@/router";

export default {
  name: "UserLogin",
  data() {
    return {
      account: '',
      password: ''
    }
  },
  methods: {
    login() {
      request.post("http://localhost:8087/user/login?account="+this.account+"&password="+this.password).then(res =>{
        if(res.flag){
          localStorage.setItem("userToken",res.data)
          router.push({path: '/front/home'});
          this.$message({
            type: 'success',
            message: res.msg
          })
        }else {
          this.$message.error(res.msg)
          this.account = ''
          this.password = ''
        }
      })
    },
    redirect() {
      router.push({path: '/regiest'});
    }
  }
}
</script>

<style>
.title11 {
  position: absolute;
  margin-left: 31%;
  top: 100px;
}

.class12 {
  /* display: inline-flex; */
  position: absolute;
  top: 300px;
  margin-left: 35%;
  text-align: center;
  font-family: fantasy;
}

.class13 {
  /* display: inline-flex; */
  position: absolute;
  top: 360px;
  margin-left: 35%;
  text-align: center;
  font-family: fantasy;
}

.class14 {
  position: absolute;
  margin-left: 39%;
  top: 410px;
  width: 260px;
  height: 35px;
  background-image: url(../assets/button-bg.jpg);
  border-radius: 5px;
  font-size: 20px;
}

.class15 {
  position: absolute;
  margin-left: 39%;
  top: 460px;
  width: 260px;
  height: 35px;
  background-image: url(../assets/button-bg.jpg);
  border-radius: 5px;
  font-size: 20px;
}

.class6 {
  text-align: center;
}

.text1 {
  height: 25px;
  width: 300px;
}

#pic {
  position: relative;
  background-repeat: no-repeat;
  width: 1500px;
  height: 1000px;
  z-index: -1;
}

.error{
  color: red;
}
</style>
